# models/file_version.py - 文件版本模型
from typing import Dict, Any
from datetime import datetime

class FileVersion:
    """文件版本信息模型"""
    
    def __init__(self, version: str, brief: str = "", description: str = "", 
                 file_name: str = "", file_size: int = 0):
        self.version = version
        self.brief = brief
        self.description = description
        self.file_name = file_name
        self.file_size = file_size
        self.upload_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    
    def to_dict(self) -> Dict[str, Any]:
        """转换为字典"""
        return {
            "version": self.version,
            "brief": self.brief,
            "description": self.description,
            "file_name": self.file_name,
            "file_size": self.file_size,
            "upload_time": self.upload_time
        }
    
    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> 'FileVersion':
        """从字典创建实例"""
        instance = cls(
            version=data.get("version", ""),
            brief=data.get("brief", ""),
            description=data.get("description", ""),
            file_name=data.get("file_name", ""),
            file_size=data.get("file_size", 0)
        )
        instance.upload_time = data.get("upload_time", instance.upload_time)
        return instance